package xiaohu.ODImportant;

public class _01 {
    public static void main(String[] args) {
        String test="12abc-abCABc-4aB@";
        int i1 = test.indexOf("-");
        String substring = test.substring(0, i1);
        System.out.println(substring);
        String str1 = test.replaceFirst(substring, "").replaceAll("-", "");
        StringBuilder stringBuilder = new StringBuilder(substring);
        if (str1.length() > 0) {
            stringBuilder.append("-");
            int lower=0;
            int upper=0;
            StringBuilder strTemp = new StringBuilder();
            for (int i = 0; i < str1.length(); i++) {
                if (Character.isLowerCase(str1.charAt(i))) {
                    lower++;
                }
                if (Character.isUpperCase(str1.charAt(i))) {
                    upper++;
                }
                strTemp.append(str1.charAt(i));
                if ((i + 1) % 3 == 0 && i != str1.length() - 1) {
                    if (lower > upper) {
                        String lowerCase = strTemp.toString().toLowerCase();
                        stringBuilder.append(lowerCase);
                        strTemp.delete(0, strTemp.length());
                    } else if (upper > lower) {
                        String upperCase = strTemp.toString().toUpperCase();
                        stringBuilder.append(upperCase);
                        strTemp.delete(0, strTemp.length());
                    } else {
                        stringBuilder.append(strTemp.toString());
                        strTemp.delete(0, strTemp.length());
                    }
                    stringBuilder.append("-");
                }
                if (i == str1.length() - 1) {
                    if (lower > upper) {
                        String lowerCase = strTemp.toString().toLowerCase();
                        stringBuilder.append(lowerCase);
                    } else if (upper > lower) {
                        String upperCase = strTemp.toString().toUpperCase();
                        stringBuilder.append(upperCase);
                    } else {
                        stringBuilder.append(strTemp.toString());
                    }
                }
            }
        }
        System.out.println(stringBuilder.toString());
    }
}
